﻿using System;
using System.IO;
using System.Xml.Serialization;
using System.Linq;
using System.Collections;

namespace SilverlightDatabase.Core
{
    public delegate void IgnoreTypeHandler(Type type, ref bool ignore);

    /// <summary>
    /// Interface that is used for tables in a database
    /// </summary>
    public interface ITable : ICollection
    {
        event IgnoreTypeHandler IgnoreType; 
        event EventHandler OnDirty;
        /// <summary>
        /// Type of object that database contains
        /// </summary>
        Type RowType { get; }

        /// <summary>
        /// Save table le to the Isolated Storage
        /// </summary>
        void Save();

        /// <summary>
        /// Write content of a table to a file stream
        /// </summary>
        /// <param name="stream">Stream to write table to</param>
        void WriteTableToStream(Stream stream);

        /// <summary>
        /// Set internal variables data when a table is de-serialized
        /// </summary>
        /// <param name="databaseName">Database name that table belongs to</param>
        /// <param name="password">Password to use for encryption</param>
        /// <param name="useCompression">Use compression for storage</param>
        void Initialize(IDatabase database, byte[] certificate, bool useCompression);
        long GetSpaceRequirements();
        long GetSpaceRequirements(XmlAttributeOverrides overrides);
        long WriteTableToStreamForSpace(Stream stream);
        long WriteTableToStreamForSpace(Stream stream, XmlAttributeOverrides overrides);
    }
}
